#include<iostream>
#include <algorithm>
#define rows 8
#define cols 8

using namespace std;

void print(int * data){
	for ( int i = 0; i< rows; i++ )
		cout << data[i] << "  ";
	cout << endl;
}

bool checkPointHashQueen(int col, int *flag){
	for ( int i = 0; i<col; i++ ){
		if ( flag[col] == flag[i] || abs(flag[col]-flag[i])==abs(col-i)){
			return false;
		}
	}
	return true;
}



void findQueen(int col, int *flag, int& count){
	if ( col == cols ){
		print(flag);
		count++;
		return;
	}
	// 遍历行
	for ( int rowIndex = 0; rowIndex < rows; rowIndex ++ ){
		flag[col] = rowIndex;
		if ( checkPointHashQueen(col, flag) ){
			findQueen(col+1, flag, count);
		}
		
	}
	// 重置
	flag[col--] = -1;
}


int main(void){
    int flag[cols] = {-1,-1,-1,-1,-1,-1,-1,-1};
    int count = 0;
    findQueen(0, flag, count);
	cout << count << endl;
    return 0;
}